package com.leetcode;

public class BuySellStock2 {
	public int maxProfit(int[] prices) {
        if (prices.length == 0) return 0;
        int max = 0;
        int low = prices[0];
        for (int i=1; i<prices.length; i++) {
        	if (prices[i] <= low) {
        		low = prices[i];
        	} else {
        		max += prices[i] - low;
        		low = prices[i];
        	}
        }
		return max;
    }
}
